﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using System.Web.SessionState;

namespace cebao.Web.harmfulinfo
{
    /// <summary>
    /// GetHarm 的摘要说明
    /// </summary>
    public class GetHarm : IHttpHandler, IRequiresSessionState
    {

        StringBuilder result = new StringBuilder();
        StringBuilder sb = new StringBuilder();
        StringBuilder rechild = new StringBuilder();
        cebao.BLL.harmfulinfo bll = new BLL.harmfulinfo();
        public void ProcessRequest(HttpContext context)
        {
            string ac = "";
            if (null != context.Request.Form["action"])
            {//获取前台传来的值  
                ac = context.Request.Form["action"].ToString().Trim();
            }
            else if (null != context.Request.QueryString["action"])
            {
                ac = context.Request.QueryString["action"].ToString().Trim();
            }
            
            if (ac == "querypro")
                Querypro(context);//本省数据
            if (ac == "queryprot")
                Queryprotype(context);//本省某类数据
            else if (ac == "query")
                Query(context);//全 国数据
            else if (ac == "querytg")
                QueryGridTree(context); //测试 
            else if (ac == "queryt")
                Queryt(context);//害加地区树
            else if (ac == "queryta")
                Queryta(context);
            else if (ac == "queryth")
                Queryth(context);
            else if (ac == "add")
                add(context);
            else if (ac == "modify")
                modify(context);
            else if (ac == "delete")
                delete(context);
            else if (ac == "queryc")
                Querychild(context);
            else if (ac == "queryr")
                QueryRoot(context);
            else if (ac == "querymy")
                Querymy(context);
            else if (ac == "addmynode")
                addmy(context);
            else if (ac == "addmyuidnode")
                addmyuid(context);
            else if (ac == "deletemy")
                deletemy(context);
            else if (ac == "deletemyuid")
                deletemyuid(context);
            else if (ac == "queryus")
                Queryus(context);//uid所在省内数据
            else if (ac == "querymyuid")
                Querymyuid(context);//uid所在省内数据


        }
        public void Queryth(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            context.Response.ContentEncoding = Encoding.UTF8;
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                cebao.BLL.myharmful mybll = new BLL.myharmful();
                StringBuilder strWhere = new StringBuilder();
                string type = context.Request.QueryString["type"];
                if (type == "1")//病
                {
                    strWhere.Append(" (LEFT(hbm,1)='1' or LEFT(hbm,1)='2') and ");
                }
                else if (type == "4")//虫
                {
                    strWhere.Append(" (LEFT(hbm,1)='4' or LEFT(hbm,1)='5' )  and ");
                }
                else if (type == "6")//鼠
                {
                    strWhere.Append(" LEFT(hbm,1)='6' and ");
                }
                else if (type == "7")//草
                {
                    strWhere.Append(" LEFT(hbm,1)='7' and ");
                }
                if (pcc[0] != "")
                {
                    strWhere.AppendFormat(" province='{0}'  and ", pcc[0]);
                }
                string wh = strWhere.ToString();
                wh = wh.Substring(0, wh.LastIndexOf("and"));
                DataSet ds = mybll.GetListv(wh);
                string str = GetTreeJsonByTablea(ds.Tables[0], "mhid", "hname", "1");
                if (str != "")
                    str = "{\"id\":-1,\"text\":\"分病虫浏览\",\"children\":" + str + "}";
                else
                    str = "{\"id\":-1,\"text\":\"分病虫浏览\",\"children\":[]}";                
                string strJson = "[" + str + "]";
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void Queryta(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            context.Response.ContentEncoding = Encoding.UTF8;
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                cebao.BLL.myharmful mybll = new BLL.myharmful();
                StringBuilder strWhere = new StringBuilder();               
                BLL.areainfo blla = new BLL.areainfo();
                int level = Web.Admin.myinfo.getLevel(context);
                int aid = blla.GetAid(level, pcc);
                string myp = "";
                string mybh = "";
                if (aid != 0)
                    mybh = blla.GetModel(aid).abh;
                if (level > 3) { myp = "全国"; mybh = "000000"; }
                else if (level == 3 || level == -1) myp = pcc[0];
                else if (level == 2) myp = pcc[1];
                else if (level == 1) myp = pcc[2];
                DataSet ds = blla.GetList("LEN(abh)<>9");
                //ds = blla.GetList("");
                result.Remove(0, result.Length);
                string strb = GetTreeJsonByTableaa(ds.Tables[0], "aid", "aname", "pid", aid);
                //string strb = GetTreeJsonByTable(ds.Tables[0], "aid", "aname", "2");
                strb = "{\"id\":-2,\"text\":\"分地区浏览\",\"children\":[{\"id\":" + aid + ",\"text\":\"" + myp + "\",\"type\":\"2\",\"bm\":\"" + mybh + "\",\"children\":" + strb + "}]}";
                string strJson = "[" + strb + "]";
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        public void Queryt(HttpContext context)
        {
            context.Response.ContentType = "text/json";
            context.Response.ContentEncoding = Encoding.UTF8;
            int uid = Web.Admin.myinfo.getID(context);
            if (uid != 0)
            {
                string[] pcc = Web.Admin.myinfo.getPCC(context).Split(',');
                cebao.BLL.myharmful mybll = new BLL.myharmful();
                StringBuilder strWhere = new StringBuilder();
                string type = context.Request.QueryString["type"];
                if (type == "1")//病
                {
                    strWhere.Append(" (LEFT(hbm,1)='1' or LEFT(hbm,1)='2') and ");
                }
                else if (type == "4")//虫
                {
                    strWhere.Append(" (LEFT(hbm,1)='4' or LEFT(hbm,1)='5' )  and ");
                }
                else if (type == "6")//鼠
                {
                    strWhere.Append(" LEFT(hbm,1)='6' and ");
                }
                else if (type == "7")//草
                {
                    strWhere.Append(" LEFT(hbm,1)='7' and ");
                } 
                if (pcc[0] != "")
                {
                    strWhere.AppendFormat(" province='{0}'  and ", pcc[0]);
                }
                string wh = strWhere.ToString();
                wh = wh.Substring(0, wh.LastIndexOf("and"));
                DataSet ds = mybll.GetListv(wh);
                string str = GetTreeJsonByTablea(ds.Tables[0], "mhid", "hname", "1");
                if(str!="")
                str = "{\"id\":-1,\"text\":\"分病虫浏览\",\"children\":" + str + "}";
                else
                    str = "{\"id\":-1,\"text\":\"分病虫浏览\",\"children\":[]}";
                BLL.areainfo blla = new BLL.areainfo();
                //ds = blla.GetList("");

                int level = Web.Admin.myinfo.getLevel(context);
                int aid = blla.GetAid(level, pcc);
                string myp = "";
                string mybh="";
                if(aid!=0)
                mybh = blla.GetModel(aid).abh;
                if (level > 3) { myp = "全国"; mybh = "000000"; }
                else if (level == 3|| level==-1) myp = pcc[0];
                else if (level == 2) myp = pcc[1];
                else if (level == 1) myp = pcc[2];
                ds = blla.GetList("LEN(abh)<>9");
                //ds = blla.GetList("");
                result.Remove(0, result.Length);
                string strb = GetTreeJsonByTableaa(ds.Tables[0], "aid", "aname", "pid", aid);
                //string strb = GetTreeJsonByTable(ds.Tables[0], "aid", "aname", "2");
                strb = "{\"id\":-2,\"text\":\"分地区浏览\",\"children\":[{\"id\":" + aid + ",\"text\":\"" + myp + "\",\"type\":\"2\",\"bm\":\""+mybh+"\",\"children\":" + strb + "}]}";
                string strJson = "[{\"id\":0,\"text\":\"全部\",\"children\":[" + str + "," + strb + "]}]";
                context.Response.Write(strJson);//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();

            }
        }
        private string GetTreeJsonByTablea(DataTable tabel, string idCol, string txtCol, string addattr)
        {
            result.Remove(0, result.Length);
            if (tabel.Rows.Count > 0)
            {
                result.Append("[");

                foreach (DataRow row in tabel.Rows)
                {
                    result.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol].ToString().Trim() + "\",\"type\":\"" + addattr + "\"},");
                }
                result = result.Remove(result.Length - 1, 1);

                result.Append("]");

            }
            return result.ToString();
        }
        public void deletemyuid(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                int uid = 0;
                string uidstr = context.Request.QueryString["uhid"];
                if (uidstr != "")
                    uid = int.Parse(uidstr);
                cebao.BLL.userharmful mybll = new BLL.userharmful();
                if (mybll.Delete(uid))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();
                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();

                }
            }

        }
        public void deletemy(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            { 
            int uid = 0;
            string uidstr = context.Request.QueryString["mhid"];
            if (uidstr != "")
                uid = int.Parse(uidstr);
            cebao.BLL.myharmful mybll = new BLL.myharmful();
            if (mybll.Delete(uid))
            {
                context.Response.Write("T");//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("F");//返回给前台页面  
                context.Response.End();

            }
            }

        }
        public void Querychild(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string pro = Web.Admin.myinfo.getPCC(context).Split(',')[0];
            string pid = context.Request.QueryString["pid"];
            StringBuilder strWhere = new StringBuilder();
            if (pro != "")
            {
                strWhere.AppendFormat(" province='{0}'  ", pro);
            }
            DataSet ds = bll.GetList(strWhere.ToString());

            string str = GetTreechild(ds.Tables[0], "hid", "parentid", pid);
            if (str == "")
                str = pid;
            else
                str += pid;
            string json = "[{\"ids\":\"" + str + "\"}]";
            context.Response.Write(json);//返回给前台页面  
            context.Response.End();

        }
        private string GetTreechild(DataTable tabel, string idCol, string rela, object pId)
        {
            rechild.Append(sb.ToString());
            sb.Remove(0, sb.Length);
            if (tabel.Rows.Count > 0)
            {
                string filer = string.Format("{0}='{1}'", rela, pId);
                DataRow[] rows = tabel.Select(filer);
                if (rows.Length > 0)
                {
                    foreach (DataRow row in rows)
                    {
                        sb.Append(row[idCol] + ",");
                        if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0)
                        {
                            GetTreechild(tabel, idCol, rela, row[idCol]);
                            rechild.Append(sb.ToString());
                            sb.Remove(0, sb.Length);
                        }
                        rechild.Append(sb.ToString());
                        sb.Remove(0, sb.Length);
                    }
                    //sb = sb.Remove(sb.Length - 1, 1);
                }
                rechild.Append(sb.ToString());
                sb.Remove(0, sb.Length);
            }
            return rechild.ToString();
        }
        public void delete(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int uid = 0;
            string uidstr = context.Request.QueryString["hid"];
            if (uidstr != "")
                uid = int.Parse(uidstr);
            if (bll.Delete(uid))
            {
                context.Response.Write("T");//返回给前台页面  
                context.Response.End();
            }
            else
            {
                context.Response.Write("F");//返回给前台页面  
                context.Response.End();

            }

        }
        public void modify(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            
            string province = Web.Admin.myinfo.getPCC(context).Split(',')[0];
            if (province != "")
            {
                decimal r = 0.00M;
                string hname = context.Request.Form["hname"];
                string hbm = context.Request.Form["hbm"];
                int hid = int.Parse(context.Request.Form["hid"]);
                string ldxm = context.Request.Form["ldxm"];
                string rstr = context.Request.Form["rvalue"];
                if (rstr != "") r = decimal.Parse(rstr);
                cebao.Model.harmfulinfo model = new cebao.Model.harmfulinfo();
                model.hname = hname;
                model.hbm = hbm;
                model.hid = hid;
                model.ldxm = ldxm;
                model.rvalue = r;
                if (bll.Update(model))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
        }
        public void add(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            
            string province = Web.Admin.myinfo.getPCC(context).Split(',')[0];
            if (province != "")
            {
                decimal r=0.00M;
                string hname = context.Request.Form["hname"];
                string hbm = context.Request.Form["hbm"];
                string ldxm = context.Request.Form["ldxm"];
                string rstr = context.Request.Form["rvalue"];
                int parentid = 0;
                if (context.Request.Form["parentid"] != "")
                    parentid = int.Parse(context.Request.Form["parentid"]);
                if (rstr != "") r = decimal.Parse(rstr);
                cebao.Model.harmfulinfo model = new cebao.Model.harmfulinfo();
                model.hname = hname;
                model.parentid = parentid;
                model.hbm = hbm;
                model.ldxm = ldxm;
                model.rvalue = r;
                //model.province = province;
                if (bll.Add(model))
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }

        }
        public void addmy(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int hid = 0;
            string hids = context.Request.QueryString["hid"];
            if (hids != "") hid = int.Parse(hids);
            if (hid != 0)
            {
            string province = Web.Admin.myinfo.getPCC(context).Split(',')[0];
            int uid = Web.Admin.myinfo.getID(context);
            if (province != "")
            {                
                cebao.Model.myharmful model = new cebao.Model.myharmful();
                model.hid = hid;
                model.uid =uid;
                model.province = province;
                cebao.BLL.myharmful mybll = new BLL.myharmful();
                if (mybll.Add(model)>0)
                {
                    context.Response.Write("T");//返回给前台页面  
                    context.Response.End();

                }
                else
                {
                    context.Response.Write("F");//返回给前台页面  
                    context.Response.End();
                }
            }
            else
            {
                context.Response.Write("L");//返回给前台页面  
                context.Response.End();
            }
            }

        }
        public void addmyuid(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            int hid = 0;
            string hids = context.Request.QueryString["hid"];
            if (hids != "") hid = int.Parse(hids);
            if (hid != 0)
            {
                string uids = context.Request.QueryString["uid"];
                int uid = 0;
                int.TryParse(uids, out uid);
                if (uid != 0)
                {
                    cebao.Model.userharmful model = new cebao.Model.userharmful();
                    model.mhid = hid;
                    model.uid = uid;

                    cebao.BLL.userharmful mybll = new BLL.userharmful();
                    if (mybll.Add(model) > 0)
                    {
                        context.Response.Write("T");//返回给前台页面  
                        context.Response.End();

                    }
                    else
                    {
                        context.Response.Write("F");//返回给前台页面  
                        context.Response.End();
                    }
                }
                else
                {
                    context.Response.Write("L");//返回给前台页面  
                    context.Response.End();
                }
            }

        }
        private string GetTreeJsonByTableaa(DataTable tabel, string idCol, string txtCol, string rela, object pId)
        {
            result.Append(sb.ToString());
            sb.Remove(0, sb.Length);
            if (tabel.Rows.Count > 0)
            {
                sb.Append("[");
                string filer = string.Format("{0}='{1}'", rela, pId);
                DataRow[] rows = tabel.Select(filer);
                if (rows.Length > 0)
                {
                    foreach (DataRow row in rows)
                    {
                        if (row[idCol].ToString() == "140")
                        {
                            string a = "";
                        }
                        sb.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol] + "\",\"type\":\"2\",\"bm\":\"" + row["abh"] + "\"");
                        if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0)
                        {
                            //点击展开
                            sb.Append(",\"children\":");
                            GetTreeJsonByTableaa(tabel, idCol, txtCol, rela, row[idCol]);
                            result.Append(sb.ToString());
                            sb.Remove(0, sb.Length);
                        }
                        result.Append(sb.ToString());
                        sb.Remove(0, sb.Length); ;
                        sb.Append("},");
                    }
                    sb = sb.Remove(sb.Length - 1, 1);
                }
                sb.Append("]");
                result.Append(sb.ToString());
                sb.Remove(0, sb.Length);
            }
            return result.ToString();
        }
        private string GetTreeJsonByTable(DataTable tabel, string idCol, string txtCol, string rela, object pId)
        {
            result.Append(sb.ToString());
            sb.Remove(0, sb.Length);
            if (tabel.Rows.Count > 0)
            {
                sb.Append("[");
                string filer = string.Format("{0}='{1}'", rela, pId);
                DataRow[] rows = tabel.Select(filer);
                if (rows.Length > 0)
                {
                    foreach (DataRow row in rows)
                    {
                        sb.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol] + "\",\"bm\":\"" + row["hbm"] + "\",\"ldxm\":\"" + row["ldxm"] + "\",\"rvalue\":\"" + row["rvalue"] + "\"");
                        if (tabel.Select(string.Format("{0}='{1}'", rela, row[idCol])).Length > 0)
                        {
                            //点击展开
                            sb.Append(",\"children\":");
                            GetTreeJsonByTable(tabel, idCol, txtCol, rela, row[idCol]);
                            result.Append(sb.ToString());
                            sb.Remove(0, sb.Length);
                        }
                        result.Append(sb.ToString());
                        sb.Remove(0, sb.Length); ;
                        sb.Append("},");
                    }
                    sb = sb.Remove(sb.Length - 1, 1);
                }
                sb.Append("]");
                result.Append(sb.ToString());
                sb.Remove(0, sb.Length);
            }
            return result.ToString();
        }
        private string GetTreeJsonByTableOne(DataTable tabel, string idCol, string txtCol, string bmCol)
        {
            result.Remove(0, result.Length);
            if (tabel.Rows.Count > 0)
            {
                result.Append("[");

                foreach (DataRow row in tabel.Rows)
                {
                    result.Append("{\"id\":\"" + row[idCol] + "\",\"text\":\"" + row[txtCol] + "\",\"bm\":\"" + row[bmCol] + "\"},");
                }
                result = result.Remove(result.Length - 1, 1);

                result.Append("]");

            }
            return result.ToString();
        }
        public void Query(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
            //string pro = Web.Admin.myinfo.getPCC(context).Split(',')[0];

            //StringBuilder strWhere = new StringBuilder();
            //if (pro != "")
            //{
            //    strWhere.AppendFormat(" province='{0}'  ", pro);
            //}
            DataSet ds = bll.GetList(" 1=1 order by hbm");

            string str = GetTreeJsonByTable(ds.Tables[0], "hid", "hname", "parentid", 0);
            
            context.Response.Write(str);//返回给前台页面  
            context.Response.End();
            }
        }
        public void Querymyuid(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                string uids = context.Request.Params["uid"];
                int uid = 0;
                int.TryParse(uids, out uid);
                cebao.BLL.myharmful mybll = new BLL.myharmful();
                //string pro = Web.Admin.myinfo.getPCC(context).Split(',')[0];
                DataSet ds = mybll.GetListvuid(" uid=" + uid );
                string str = GetTreeJsonByTableOne(ds.Tables[0], "uhid", "hname", "hbm");
                context.Response.Write(str);//返回给前台页面  
                context.Response.End();
            }
        }
        public void Querymy(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                cebao.BLL.myharmful mybll = new BLL.myharmful();
                string pro = Web.Admin.myinfo.getPCC(context).Split(',')[0];
                DataSet ds = mybll.GetListv(" province='" + pro+"'");
                string str = GetTreeJsonByTableOne(ds.Tables[0], "mhid", "hname", "hbm");
                context.Response.Write(str);//返回给前台页面  
                context.Response.End();
            }
        }
        public void Queryus(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                BLL.userinfo ubll = new BLL.userinfo();
                string uids = context.Request.Params["uid"];
                int uid = 0;
                int.TryParse(uids, out uid);
                cebao.BLL.myharmful mybll = new BLL.myharmful();
                string pro = ubll.Getpro(uid);
                DataSet ds = mybll.GetListv(" province='" + pro + "'");
                string str = GetTreeJsonByTableOne(ds.Tables[0], "mhid", "hname", "hbm");
                context.Response.Write(str);//返回给前台页面  
                context.Response.End();
            }
        }
        public void Queryprotype(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                string pro = Web.Admin.myinfo.getPCC(context).Split(',')[0];
                StringBuilder strWhere = new StringBuilder();
                string type = context.Request.QueryString["type"];
                if (type == "1")//病
                {
                    strWhere.Append(" LEFT(hbm,1)='1' and ");
                }
                else if (type == "4")//虫
                {
                    strWhere.Append(" (LEFT(hbm,1)='4' or LEFT(hbm,1)='5' )  and ");
                }
                else if (type == "6")//鼠
                {
                    strWhere.Append(" LEFT(hbm,1)='6' and ");
                }
                else if (type == "7")//草
                {
                    strWhere.Append(" LEFT(hbm,1)='7' and ");
                } if (pro != "")
                {
                    strWhere.AppendFormat(" province='{0}'  and ", pro);
                }
                cebao.BLL.myharmful mybll = new BLL.myharmful();
                string wh = strWhere.ToString();
                wh = wh.Substring(0, wh.LastIndexOf("and"));
                DataSet ds = mybll.GetListv(wh);
                string str = GetTreeJsonByTableOne(ds.Tables[0], "mhid", "hname", "hbm");
                str = "[{\"id\":0,\"text\":\"全部\",\"children\":" + str + "}]";
                context.Response.Write(str);//返回给前台页面  
                context.Response.End();
            }
        }
        public void Querypro(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {
                string pro = Web.Admin.myinfo.getPCC(context).Split(',')[0];

                StringBuilder strWhere = new StringBuilder();
                if (pro != "")
                {
                    strWhere.AppendFormat(" province='{0}'  ", pro);
                }
                cebao.BLL.myharmful mybll = new BLL.myharmful();                
                DataSet ds = mybll.GetListv(strWhere.ToString());
                string str = GetTreeJsonByTableOne(ds.Tables[0], "mhid", "hname", "hbm");
                context.Response.Write(str);//返回给前台页面  
                context.Response.End();
            }
        }
        public void QueryRoot(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string pro = Web.Admin.myinfo.getPCC(context).Split(',')[0];

            StringBuilder strWhere = new StringBuilder();
            if (pro != "")
            {
                strWhere.AppendFormat(" province='{0}'  ", pro);
            }
            cebao.BLL.myharmful mybll = new BLL.myharmful(); 
            DataSet ds = mybll.GetListv(strWhere.ToString());

            string str = GetTreeJsonByTableOne(ds.Tables[0], "mhid", "hname", "hbm");
            str = "[{\"id\":0,\"text\":\"全部\",\"children\":" + str + "}]";
            context.Response.Write(str);//返回给前台页面  
            context.Response.End();

        }
        public void QueryGridTree(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            if (Web.Admin.myinfo.isLogin(context))
            {                
                DataSet ds = bll.GetList("");
                //string str = ToJson.Dataset2Json(ds, ds.Tables[0].Rows.Count, 50);
                string str = cebao.Common.JsonHelper.DataTable2TreeJson("hid", "hname", "parentid", 0, ds.Tables[0], 0);
                context.Response.Write(str);//返回给前台页面  
                context.Response.End();
            }
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}